{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "import tensorflow as tf\n",
    "import numpy as np\n",
    "import shutil"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "shutil.rmtree(\"outdir\", ignore_errors = True) # start fresh each time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "def train_input_fn():\n",
    "    features = {\"sq_footage\": [ 1000,    2000,    3000,    1000,  2000,  3000],\n",
    "                \"type\":       [\"house\", \"house\", \"house\", \"apt\", \"apt\", \"apt\"]}\n",
    "    labels =                  [ 500,     1000,    1500,    700,   1300,  1900] # in thousands\n",
    "    return features, labels\n",
    "\n",
    "featcols = [\n",
    "    tf.feature_column.numeric_column(\"sq_footage\"),\n",
    "    tf.feature_column.categorical_column_with_vocabulary_list(\"type\", [\"house\", \"apt\"])\n",
    "]\n",
    "\n",
    "model = tf.estimator.LinearRegressor(featcols, \"outdir\")\n",
    "                                     \n",
    "model.train(train_input_fn, steps=2000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "def predict_input_fn():\n",
    "    features = {\"sq_footage\": [1500, 1500, 2500, 2500],\n",
    "                \"type\": [\"house\", \"apt\", \"house\", \"apt\"]}\n",
    "    return features\n",
    "\n",
    "predictions = model.predict(predict_input_fn)\n",
    "\n",
    "print(next(predictions))\n",
    "print(next(predictions))\n",
    "print(next(predictions))\n",
    "print(next(predictions))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
